//
//  EditCarInfoVC.m
//  New_Runway
//
//  Created by mack on 2018/1/26.
//  Copyright © 2018年 NelsonJ. All rights reserved.
//

#import "EditCarInfoVC.h"
#import "CarSetListCell.h"
#import "PickDateView.h"
#import "PickCustomView.h"
#import "MarketModel.h"
#import "ShopModel.h"
//#import "PickCarView.h"
#import "CarSeriesModel.h"
#import "CarVersionModel.h"
#import "PickCarColorView.h"
//#import "ColorModel.h"
#import "CarTypeModel.h"
#import "EditCarinfoSecondVC.h"
#import "CrmIsArriveShopCell.h"
#import "CarInputChooseBrandVC.h"
#import "CarInputChooseModel.h"
#import "YTServerAPI.h"
#import "CarVinAuthOCRVC.h"
#import "CarmodelConfigModel.h"
#import "CarInfoFormVinModel.h"
#import "CarInfoOtherConfModel.h"
#import "CarRejectReasonView.h"
#import "NRWCar300Model.h"
@interface EditCarInfoVC ()<UITableViewDelegate,UITableViewDataSource,UITextFieldDelegate,PickerDateViewDelegate,CustomPickViewDelegate,carColorPickViewDelegate,UIActionSheetDelegate,UINavigationControllerDelegate,UIImagePickerControllerDelegate>
@property(nonatomic, strong) UITableView *tableview;
@property (nonatomic, strong) NSMutableArray *marketArray;
@property (nonatomic, strong) NSMutableArray *seriesArray;
@property (nonatomic, strong) NSMutableArray *carVersionArray;
@property (nonatomic, strong) NSMutableArray *colorsArray;
@property (nonatomic, assign) BOOL isPrice;
@property (nonatomic, assign) BOOL isRequired;
@property (nonatomic, assign) BOOL isExpire;
@property (nonatomic, strong) CarmodelConfigModel *model;
@property (nonatomic, strong) CarInfoOtherConfModel *otherModel;
@property (nonatomic, strong) NSMutableArray *useKeys;
@property (nonatomic, strong) NSMutableArray *typeIds;
@property (nonatomic, strong) CarRejectReasonView *rejectView;
@property (nonatomic, copy) NSString *reasonStr;
@property (nonatomic, strong) NRWCar300Model *car300Model;
@property (nonatomic, strong) NSMutableArray *car300ModelArray;
@end

@implementation EditCarInfoVC
{
    BOOL isShowDay;//是否显示日信息
    NSString *_dateStr;//日期
    NSString *_markName;
    NSString *_markID;//市场区域
    NSString *_shopName;
    NSString *_shopID;//商铺
    NSString *_carBrangName;
    NSString *_carBrangID;//车品牌
    NSString *_seriesName;
    NSInteger _seriesID;//车系
    NSString *_carModelName;
    NSInteger _carModelId;//车型号
    NSString *_carNum;//车架号
    NSString *_kilometre;//公里数
    NSString *_License;//牌照
    NSString *_LicenseID;
    NSString *_firstDate;//首次上牌时间
    NSString *_checkDate;//年审日期
    NSString *_bizDate;//商业险日期
    NSString *_strongDate;//交强险日期
    NSString *_keyNum;//钥匙数
    NSString *_outsideColor;//外观色
    NSString *_outSideColorId;
    NSString *_insideColor;//内饰颜色
    NSString *_carType;//车身类型
    NSInteger _carTypeId;
    NSString *_boxType;//变速箱类型
    NSString *_TransferNum;//过户次数
    NSString *_outputVolume;//排量
    NSString *_outType;
    NSString *_zeroPrice;//零售价
    NSString *_carTitle;
    NSString * _modelEnviron;
    NSString *_modelFuelRoz;
    NSString *_carUseType;
    NSString *_carUserId;
    NSString *_car300Value;
}
-(NSMutableArray *)marketArray{
    if (!_marketArray) {
        _marketArray = [[NSMutableArray alloc] init];
    }
    return _marketArray;
}

-(NSMutableArray *)seriesArray{
    if (!_seriesArray) {
        _seriesArray = [[NSMutableArray alloc] init];
    }
    return _seriesArray;
    
}
-(NSMutableArray *)carVersionArray{
    if (!_carVersionArray) {
        _carVersionArray = [[NSMutableArray alloc] init];
    }
    return _carVersionArray;
    
}
-(NSMutableArray *)colorsArray{
    if (!_colorsArray) {
        _colorsArray = [[NSMutableArray alloc] init];
    }
    return _colorsArray;
}

-(CarInfoOtherConfModel *)otherModel{
    if (!_otherModel) {
        _otherModel = [[CarInfoOtherConfModel alloc] init];
    }
    return _otherModel;
}
-(NSMutableArray *)car300ModelArray{
    if (!_car300ModelArray) {
        _car300ModelArray = [[NSMutableArray alloc] init];
    }
    return _car300ModelArray;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationBarView.titleLabel.text = self.titleL;
    self.view.backgroundColor = kColorWhite();
    [self.navigationBarView.rightItem setTitle:@"下一步" forState:UIControlStateNormal];
    [self setKey];
    
    if ([self.titleL isEqualToString:@"申请入库"]) {
        self.isRequired = YES;
    }else{
        self.isRequired = NO;
    }
    [self loadCarOtherConfInfo];
    [self initTableview];
    if (self.isReject == 1) {
        [self loadRefuseReasonDataWithCarId:self.infomodel.result.carId];
    }
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(brandSearch:)name:@"ChooseCar" object:nil];

}
-(void)loadRefuseReasonDataWithCarId:(NSString *)carId{
    NSString *url = [NSString stringWithFormat:@"%@%@",Api,carRefuseApi];
    NSDictionary *params = @{@"carId":carId,@"carStateKey":@"carStockState",@"carStateValue":@1};
    [YQNetworking postWithUrl:url refreshRequest:YES cache:NO params:params progressBlock:^(int64_t bytesRead, int64_t totalBytes) {
        
    } successBlock:^(id response) {
        if ([response[@"code"] isEqual:@1]) {
            NSArray *dataArray = response[@"result"];
            if (dataArray.count != 0) {
                NSDictionary *dic = [dataArray lastObject];
                self.reasonStr = dic[@"carLogInfo"];
            }
            [self.view addSubview:self.rejectView];
        }else{
            [ShowMessage showHintMessage:response[@"msg"] duration:2.0 withRemindId:remindFail];

        }
       

    } failBlock:^(NSError *error) {
        [ShowMessage showHintMessage:@"请求失败请检查网络" duration:2.0 withRemindId:remindFail];
    }];
    
    
}
-(CarRejectReasonView *)rejectView{
    if (!_rejectView) {
        _rejectView = [[[NSBundle mainBundle] loadNibNamed:@"CarRejectReasonView" owner:self options:nil]lastObject];
        _rejectView.frame = CGRectMake(0, Screen_height - self.BotH - 35, Screen_width, 35);
        _rejectView.contentL.text = self.reasonStr;
        kSelfWeak;
        _rejectView.rejectBlock = ^(BOOL isShow) {
            if (isShow == YES) {
                 weakSelf.rejectView.frame = CGRectMake(0, Screen_height - weakSelf.BotH - 150, Screen_width, 150);
                [weakSelf.tableview mas_updateConstraints:^(MASConstraintMaker *make) {
                    make.bottom.equalTo(weakSelf.view).mas_equalTo(-weakSelf.BotH - 150);

                }];
            }else{
                weakSelf.rejectView.frame = CGRectMake(0, Screen_height - weakSelf.BotH -35, Screen_width, 35);
                [weakSelf.tableview mas_updateConstraints:^(MASConstraintMaker *make) {
                    make.bottom.equalTo(weakSelf.view).mas_equalTo(-weakSelf.BotH - 35);
                    
                }];
            }
        };
    }
    return _rejectView;
}

-(void)brandSearch:(NSNotification *)info{
    CarInputChooseModel *model = info.object;
    if ([model isKindOfClass:[CarInputChooseModel class]]) {
        _carBrangName = model.brandName;
        _carBrangID = [NSString stringWithFormat:@"%zd",model.brandId];
        _seriesID = model.seriesId;
        _seriesName = model.seriesName;
        _carModelId = model.modelId;
        _carModelName = model.modelName;
        _carTitle = [NSString stringWithFormat:@"%@%@%@",_carBrangName,_seriesName,_carModelName];
        [self loadCarModelConfigInfo:_carModelId];
        [self loadCarAbountValue];

    } else {
        NSLog(@"通知obj类型错误");
    }
    
}
-(void)loadCarModelConfigInfo:(NSInteger)modelId{
    [SVProgressHUD show];
    NSString *url = [NSString stringWithFormat:@"%@%@",Api,getCarConfigApi];
    [YQNetworking postWithUrl:url refreshRequest:YES cache:NO params:@{@"modelId":@(modelId)} progressBlock:^(int64_t bytesRead, int64_t totalBytes) {
        
    } successBlock:^(id response) {
        if ([response[@"code"] isEqual:@1]) {
            for (NSDictionary *dic in response[@"result"]) {
                CarmodelConfigModel *model = [[CarmodelConfigModel alloc] init];
                [model setValuesForKeysWithDictionary:dic];
                self.model = model;
            }
        }
        if (self.model.modelDisplacement) {
            _outputVolume = [NSString stringWithFormat:@"%.1f",self.model.modelDisplacement];
            
        }else{
            _outputVolume = @"";
            
        }
        if (isEmptyOrNilString(self.model.modelInletModel) == YES) {
            _outType = @"L";
        }else{
            _outType = self.model.modelInletModel;
        }
        self.infomodel.result.carEnviron = self.model.modelEnviron ? self.model.modelEnviron : @"";
        self.infomodel.result.carFuel = self.model.modelFuelRoz ? self.model.modelFuelRoz : @"";
        _boxType = self.model.modelGearboxModality ? self.model.modelGearboxModality : @"";
        [self.tableview reloadData];
        [SVProgressHUD dismiss];
    } failBlock:^(NSError *error) {
//        [ShowMessage showHintMessage:@"请求失败!" duration:2.0 withRemindId:remindFail];

    }];
    
}

-(void)setKey{
//        self.infomodel = self.parems[@"info"];
        _markName = self.infomodel.result.region.regionName;
        _markID = self.infomodel.result.region.regionId ;//市场区域
        _shopName = self.infomodel.result.shop.shopName;
        _shopID = self.infomodel.result.shop.shopId;//商铺
        _carBrangName = self.infomodel.result.brand.brandName;
    if (self.infomodel.result.brand.brandId) {
        _carBrangID = [NSString stringWithFormat:@"%zd",self.infomodel.result.brand.brandId];//车品牌
    }else{
        _carBrangID = @"";
    }
        _seriesName = self.infomodel.result.series.seriesName;
        _seriesID = self.infomodel.result.series.seriesId;//车系
        _carModelName = self.infomodel.result.model.modelName;
        _carModelId = self.infomodel.result.model.modelId;//车型号
        _carNum = self.infomodel.result.carVin;//车架号
    
    if ([self.infomodel.result.carMileage doubleValue] <= 0) {
        _kilometre = @"";
    }else{
        
       _kilometre = [NSString stringWithFormat:@"%.4f",[self.infomodel.result.carMileage doubleValue]];;
    }
        if (self.infomodel.result.carLicenceState == 1) {
            _License = @"已上牌";
            _LicenseID = @"1";
        }else if (self.infomodel.result.carLicenceState == 2){
            _License = @"未上牌";
            _LicenseID = @"2";
        }else if (self.infomodel.result.carLicenceState == 3){
            _License = @"新车";
            _LicenseID = @"3";
        }else{
            _License = @"已上牌";
            _LicenseID = @"1";
        }
    
        if (self.infomodel.result.carKeyNum) {
            
            _keyNum = [NSString stringWithFormat:@"%zd",self.infomodel.result.carKeyNum];//钥匙数
        }else{
            _keyNum = @"";
        }
    _outsideColor =self.infomodel.result.carOutColor;//外观色
    _outSideColorId = @"";
    _insideColor = self.infomodel.result.carInColor;//内饰颜色
    _carType = self.infomodel.result.carType.carTypeName;//车身类型
     _carTypeId = self.infomodel.result.carType.carTypeId;
    _boxType = self.infomodel.result.carGearbox;//变速箱类型
    if (self.infomodel.result.carTransferNum) {
        _TransferNum = [NSString stringWithFormat:@"%zd", self.infomodel.result.carTransferNum];
        
    }else{
        _TransferNum = @"";
    }
    if ([self.infomodel.result.carDisplacement StringIsNullOrEmpty:self.infomodel.result.carDisplacement]) {
        _outputVolume = @"";
    }else{
       
        _outputVolume = self.infomodel.result.carDisplacement;//排量
        
    }
    if (isEmptyOrNilString(self.infomodel.result.carInletModel) == YES) {
        _outType = @"L";
    }else{
        _outType =  self.infomodel.result.carInletModel;
    }
    if (self.infomodel.result.carRetailPrice > 0) {
        _zeroPrice = [NSString stringWithFormat:@"%.2f",self.infomodel.result.carRetailPrice];//零售价

    }else{
        _zeroPrice = @"";
    }
    _carTitle = [NSString stringWithFormat:@"%@%@%@",_carBrangName,_seriesName,_carModelName];
    if (self.infomodel.result.carRetailPrice <= 0) {
        self.isPrice = YES;
    }else{
        self.isPrice = NO;
    }
  
    if ([self.infomodel.result.carPurpose isEqualToString:@"1"]) {
        _carUseType = @"营运";
    }else if ([self.infomodel.result.carPurpose isEqualToString:@"2"]) {
        _carUseType = @"非营运";
    }else if ([self.infomodel.result.carPurpose isEqualToString:@"3"]) {
        _carUseType = @"营转非";
    }else{
        _carUseType = @"非营运";
    }
    if (isEmptyOrNilString(self.infomodel.result.carPurpose) == YES) {
        _carUserId = @"2";
    }else{
        _carUserId = self.infomodel.result.carPurpose;
    }
    [self setCarDate];
}
-(void)setCarDate{
    if (self.infomodel.result.carLicenceDate) {
        _firstDate = [NRWCarTurnTime timestampSwitchTime:self.infomodel.result.carLicenceDate andFormatter:@"yyyy-MM"];//首次上牌时间
    }else{
        _firstDate = @"";
    }
    
    if (self.infomodel.result.carValidateDate) {
        _checkDate = [NRWCarTurnTime timestampSwitchTime:self.infomodel.result.carValidateDate andFormatter:@"yyyy-MM"];//年审日期
    }else{
        _checkDate = @"";
    }
    if (self.infomodel.result.carBusinessInsuranceDate) {
        _bizDate = [NRWCarTurnTime timestampSwitchTime:self.infomodel.result.carBusinessInsuranceDate andFormatter:@"yyyy-MM"];//商业险日期
    }else{
        _bizDate = @"";
    }
    
    if (self.infomodel.result.carForceInsuranceDate) {
        _strongDate = [NRWCarTurnTime timestampSwitchTime:self.infomodel.result.carForceInsuranceDate andFormatter:@"yyyy-MM"];//交强险日期
    }else{
        _strongDate = @"";
    }
    if (self.infomodel.result.carBusinessInsuranceDate != 0) {
        self.isExpire = NO;
    }else{
        self.isExpire = YES;
    }
    [self loadCarAbountValue];
}

-(void)initTableview{
    kSelfWeak;
    NSInteger height = 0;
    if (self.isReject == 1) {
        height = 35;
    }
    self.tableview = [[UITableView alloc] init];
    self.tableview.delegate = self;
    self.tableview.dataSource = self;
    self.tableview.backgroundColor = MAIN_COLOR();
    self.tableview.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.tableview registerClass:[CarSetListCell class] forCellReuseIdentifier:@"CarSetListCell"];
    [self.tableview registerNib:[UINib nibWithNibName:@"CrmIsArriveShopCell" bundle:nil] forCellReuseIdentifier:@"CrmIsArriveShopCell"];
    
    [self.tableview registerClass:[UITableViewCell class] forCellReuseIdentifier:@"CELL"];
    [self.view addSubview:self.tableview];
    [self.tableview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.view).mas_equalTo(self.navH);
        make.bottom.equalTo(weakSelf.view).mas_equalTo(-self.BotH - height);
        make.left.right.equalTo(weakSelf.view);
    }];
    
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    

    if ([NRWCarUser sharedUser].shopId) {
        if (indexPath.row == 1) {
            return 0.001;
        }
    }
    if (self.isPrice == YES) {
        if (indexPath.row ==21) {
            return 0.0001;
        }
    }
    if (self.isExpire == YES) {
        if (indexPath.row == 10) {
            return 0.0001;
        }
    }
    if (indexPath.row == 7 || indexPath.row == 8 || indexPath.row == 9||indexPath.row == 10 || indexPath.row == 11 || indexPath.row == 19) {
        if ([_LicenseID intValue] == 2 || [_LicenseID intValue] == 3){
            return 0.0001;
        }
    }
 
    return 45;
    
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
        return 23;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
   
    NSArray *array = @[@"车场区域",@"商铺列表",@"车架号",@"品牌车系",@"宣传标题",@"行驶里程",@"是否已上牌",@"首次上牌年月",@"年审日期",@"商业险到期",@"商业险日期",@"交强险日期",@"钥匙数量",@"外观颜色",@"内饰颜色",@"车身类型",@"变速箱",@"过户次数",@"排量",@"建议零售价",@"",@"零售价",@"使用性质"];
    NSArray *holder = @[@"请选择车场区域",@"请选择商铺",@"请填写17位字母数数字组成的编码",@"请选择车品牌车系",@"请填写宣传标题",@"请填写公里数",@"是否已上牌",@"请选择上牌日期",@"请选择年审日期",@"",@"请选择商业险日期",@"请选择交强险日期",@"请选择钥匙数量",@"请选择外观颜色",@"请选择内饰颜色",@"请选择车身类型",@"请选择变速箱",@"请填写过户次数",@"请输入排量",@"如未显示可点击获取",@"",@"请输入零售价",@"请选择使用性质"];
    
        if (indexPath.row == 20) {
            CrmIsArriveShopCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CrmIsArriveShopCell"];
            cell.index = indexPath;
            cell.layer.masksToBounds = YES;
            if (self.isPrice == YES) {
                [cell.isYesB setImage:[UIImage imageNamed:@"crm_seleted_s"] forState:UIControlStateNormal];
                [cell.isYesB setTitleColor:MAIN_NAV_COLOR() forState:UIControlStateNormal];
                [cell.isNoB setImage:[UIImage imageNamed:@"crm_seleted_n"] forState:UIControlStateNormal];
                [cell.isNoB setTitleColor:MAIN_FONT_COLOR() forState:UIControlStateNormal];
            }else{
                [cell.isYesB setImage:[UIImage imageNamed:@"crm_seleted_n"] forState:UIControlStateNormal];
                [cell.isYesB setTitleColor:MAIN_FONT_COLOR() forState:UIControlStateNormal];
                [cell.isNoB setImage:[UIImage imageNamed:@"crm_seleted_s"] forState:UIControlStateNormal];
                [cell.isNoB setTitleColor:MAIN_NAV_COLOR() forState:UIControlStateNormal];
            }
            
            cell.mianLabel.text = @"价格面议";
            return cell;
            
        }else if (indexPath.row == 9){
            CrmIsArriveShopCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CrmIsArriveShopCell"];
            cell.index = indexPath;
             cell.layer.masksToBounds = YES;
            if (self.isExpire == YES) {
                [cell.isYesB setImage:[UIImage imageNamed:@"crm_seleted_s"] forState:UIControlStateNormal];
                [cell.isYesB setTitleColor:MAIN_NAV_COLOR() forState:UIControlStateNormal];
                [cell.isNoB setImage:[UIImage imageNamed:@"crm_seleted_n"] forState:UIControlStateNormal];
                [cell.isNoB setTitleColor:MAIN_FONT_COLOR() forState:UIControlStateNormal];
            }else{
                [cell.isYesB setImage:[UIImage imageNamed:@"crm_seleted_n"] forState:UIControlStateNormal];
                [cell.isYesB setTitleColor:MAIN_FONT_COLOR() forState:UIControlStateNormal];
                [cell.isNoB setImage:[UIImage imageNamed:@"crm_seleted_s"] forState:UIControlStateNormal];
                [cell.isNoB setTitleColor:MAIN_NAV_COLOR() forState:UIControlStateNormal];
            }
            cell.mianLabel.text = array[indexPath.row];
            return cell;
        }

    CarSetListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CarSetListCell"];
    cell.layer.masksToBounds = YES;
    cell.label.text  = array[indexPath.row];
    cell.centerTF.tag = indexPath.row;
    cell.centerTF.placeholder = holder[indexPath.row];
    cell.switchButton.hidden = YES;
    cell.centerLabel.hidden = YES;
    cell.centerTF.delegate = self;
    cell.centerTF.keyboardType = UIKeyboardTypeDefault;
    cell.rightImage.hidden = NO;
    [cell.rightImage setTitle:@"" forState:UIControlStateNormal];
    [cell.rightImage setImage:[UIImage imageNamed:@"up"] forState:UIControlStateNormal];
    cell.centerTF.userInteractionEnabled = NO;
    cell.StarL.hidden = YES;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;

    if (indexPath.row == 0 ) {
        cell.centerTF.text = _markName;
        if (self.isRequired == YES) {
            cell.StarL.hidden = NO;
        }
    }else if (indexPath.row == 1){
       
        cell.centerTF.text = _shopName;
        cell.rightImage.hidden = YES;
        if (self.isRequired == YES) {
            cell.StarL.hidden = NO;
        }
        
    }else if (indexPath.row == 2){
        
        cell.centerTF.userInteractionEnabled = YES;
        cell.rightImage.hidden = NO;
        [cell.rightImage setImage:[UIImage imageNamed:@"vin"] forState:UIControlStateNormal];
        [cell.rightImage setTitle:@"" forState:UIControlStateNormal];
        cell.centerTF.keyboardType = UIKeyboardTypeNumbersAndPunctuation;
        cell.centerTF.text = _carNum;
        cell.StarL.hidden = NO;
        if (_infomodel.result.carStockState == 20) {
            cell.centerTF.userInteractionEnabled = NO;
            cell.rightImage.hidden = YES;
            
        }
    }else if (indexPath.row == 3){
        cell.centerTF.text = _carBrangName;
        cell.StarL.hidden = NO;
        if (_infomodel.result.carStockState == 20) {
            cell.rightImage.hidden = YES;
        }
        
    }else if (indexPath.row == 4){
        cell.centerTF.userInteractionEnabled = YES;
        cell.centerTF.text = [NSString stringWithFormat:@"%@%@%@",_carBrangName,_seriesName,_carModelName];
        cell.rightImage.hidden = YES;
        cell.StarL.hidden = NO;
        
    }else if (indexPath.row == 5){
        cell.centerTF.userInteractionEnabled = YES;
        if (_infomodel.result.carStockState == 20 && [self.infomodel.result.carMileage doubleValue] > 0) {
            cell.centerTF.userInteractionEnabled = NO;
        }
        cell.centerTF.keyboardType = UIKeyboardTypeDecimalPad;
        cell.rightImage.hidden = NO;
        [cell.rightImage setTitle:@"万公里" forState:UIControlStateNormal];
        [cell.rightImage setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
        cell.centerTF.text = _kilometre;
        if (self.isRequired == YES) {
            cell.StarL.hidden = NO;
        }
        
    }else if (indexPath.row == 6 ){
      
        cell.centerTF.text = _License;
        if (self.isRequired == YES) {
            cell.StarL.hidden = NO;
        }
        if (_infomodel.result.carStockState == 20) {
            cell.rightImage.hidden = YES;
        }
    }else if (indexPath.row == 7){
      
        if ([_LicenseID intValue] == 2 || [_LicenseID intValue] == 3) {
            cell.centerTF.text = @"";
        }else{
            cell.centerTF.text = _firstDate;
        }
        if (self.isRequired == YES) {
            cell.StarL.hidden = NO;
        }
        if (_infomodel.result.carStockState == 20 && self.infomodel.result.carLicenceDate > 0) {
            cell.rightImage.hidden = YES;
        }
    }else if (indexPath.row == 8){
     
        cell.centerTF.text = _checkDate;
        if (self.isRequired == YES) {
            cell.StarL.hidden = NO;
        }
        if (_infomodel.result.carStockState == 20 && self.infomodel.result.carVehicletaxDate > 0) {
            cell.rightImage.hidden = YES;
        }
    }else if (indexPath.row == 10){
        
        cell.centerTF.text = _bizDate;
    }else if (indexPath.row == 11){
        cell.centerTF.text = _strongDate;
        if (self.isRequired == YES) {
            cell.StarL.hidden = NO;
        }
        
    }else if (indexPath.row == 12){
        [cell.rightImage setTitle:@"把" forState:UIControlStateNormal];
        [cell.rightImage setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
        cell.centerTF.text = _keyNum;
    }else if (indexPath.row == 13){
        if (_infomodel.result.carStockState == 20) {
            cell.rightImage.hidden = YES;
        }
        cell.centerTF.text = _outsideColor;
        cell.StarL.hidden = NO;

    }else if (indexPath.row == 14){
        
        cell.centerTF.text = _insideColor;
    }else if (indexPath.row == 15){
        cell.centerTF.text = _carType;
    }else if (indexPath.row == 16){
        cell.centerTF.text = _boxType;
        if (self.isRequired == YES) {
            cell.StarL.hidden = NO;
        }
    }else if (indexPath.row == 17){
        cell.centerTF.keyboardType = UIKeyboardTypeNumberPad;
        cell.centerTF.userInteractionEnabled = YES;
        cell.centerTF.text = _TransferNum;
        [cell.rightImage setTitle:@"次" forState:UIControlStateNormal];
        [cell.rightImage setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
    }else if (indexPath.row == 18){
        cell.centerTF.keyboardType = UIKeyboardTypeDecimalPad;
        cell.centerTF.userInteractionEnabled = YES;
        cell.centerTF.text = [NSString stringWithFormat:@"%@",_outputVolume];
        [cell.rightImage setTitle:_outType forState:UIControlStateNormal];
        [cell.rightImage setImage:[UIImage imageNamed:@"triangle"] forState:UIControlStateNormal];
        if (self.isRequired == YES) {
            cell.StarL.hidden = NO;
        }
        
    }else if (indexPath.row == 19){
        [cell.rightImage setImage:nil forState:UIControlStateNormal];
        [cell.rightImage setTitle:@"万元" forState:UIControlStateNormal];
        cell.centerTF.text = _car300Value;
        
    }else if (indexPath.row == 21){
        cell.centerTF.keyboardType = UIKeyboardTypeDecimalPad;
        cell.centerTF.text = _zeroPrice;
        [cell.rightImage setTitle:@"万元" forState:UIControlStateNormal];
        [cell.rightImage setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
        cell.centerTF.userInteractionEnabled = YES;
        if (self.isRequired == YES) {
            cell.StarL.hidden = NO;
        }

    }else if (indexPath.row == 22){
        if (self.isRequired == YES) {
            cell.StarL.hidden = NO;
        }
        if (_infomodel.result.carStockState == 20) {
            cell.rightImage.hidden = YES;
        }
        cell.centerTF.text = _carUseType;
    }
    return cell;
    
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    [[[UIApplication sharedApplication] keyWindow] endEditing:YES];//关闭键盘
    
    if (indexPath.row == 0) {
    
        [self loadMarketList];
        
    }else if (indexPath.row == 1){
        [ShowMessage showHintMessage:@"不可修改车商信息" duration:2.0 withRemindId:remindWarning];

    }else if (indexPath.row == 3){
        if (_infomodel.result.carStockState == 20 && isEmptyOrNilString(_carTitle) == NO) {
            [ShowMessage showHintMessage:@"入库后此信息不可更改" duration:2.0 withRemindId:remindWarning];
            return;
        }
        CarInputChooseBrandVC *brandVC = [[CarInputChooseBrandVC alloc] init];
        brandVC.fromControllerClass = self.class;
        [self.navigationController pushViewController:brandVC animated:YES];
    }else if (indexPath.row == 2){
        if (_infomodel.result.carStockState == 20) {
            [ShowMessage showHintMessage:@"入库后此信息不可更改" duration:2.0 withRemindId:remindWarning];
            return;
        }
        CarVinAuthOCRVC *codeVC = [[CarVinAuthOCRVC alloc] init];
        kSelfWeak;
        codeVC.getVin = ^(NSString *vin, NSString *time, BOOL istureVin) {
            _carNum = vin;
            if (isEmptyOrNilString(time) == NO) {
                NSInteger lenght = time.length;
                _firstDate = [time substringToIndex:lenght -3];
                _LicenseID = @"1";
                NSString *yearNum = [NRWCarTurnTime formateFirstDate:time withFormate:@"yyyy-MM-dd"];
                _checkDate = [NRWCarTurnTime returnDate:time withFormate:@"yyyy-MM-dd" withYearNum:yearNum withType:YES];
                _strongDate = _bizDate = [NRWCarTurnTime returnDate:time withFormate:@"yyyy-MM-dd" withYearNum:yearNum withType:NO];
                self.isExpire = NO;
            }
          
            [weakSelf.tableview reloadData];
        };
        [self.navigationController pushViewController:codeVC animated:YES];
    }else if (indexPath.row == 5){
        if (_infomodel.result.carStockState == 20 && [self.infomodel.result.carMileage doubleValue] > 0) {
            [ShowMessage showHintMessage:@"入库后此信息不可更改" duration:2.0 withRemindId:remindWarning];
            return;
        }
    }else if (indexPath.row == 6){
        if (_infomodel.result.carStockState == 20 ) {
            [ShowMessage showHintMessage:@"入库后此信息不可更改" duration:2.0 withRemindId:remindWarning];
            return;
        }
        NSMutableArray *names = [[NSMutableArray alloc]initWithObjects:@"已上牌",@"未上牌",@"新车", nil];
        [self creatChoose:names tag:4];

    }else if (indexPath.row == 7){
        if (_infomodel.result.carStockState == 20 && self.infomodel.result.carLicenceDate > 0) {
            [ShowMessage showHintMessage:@"入库后此信息不可更改" duration:2.0 withRemindId:remindWarning];
            return;
        }
        [self CreatDateChoose:0];
        
    }else if (indexPath.row == 8){
        if (_infomodel.result.carStockState == 20 && self.infomodel.result.carVehicletaxDate > 0) {
            [ShowMessage showHintMessage:@"入库后此信息不可更改" duration:2.0 withRemindId:remindWarning];
            return;
        }
        [self CreatDateChoose:2];

    }else if (indexPath.row == 10){
        [self CreatDateChoose:3];

    }else if (indexPath.row == 11){
        
        [self CreatDateChoose:4];

    }else if (indexPath.row == 12){
        NSMutableArray *names = [[NSMutableArray alloc]initWithObjects:@"1",@"2",@"3",@"4", nil];
        [self creatChoose:names tag:5];
    }else if (indexPath.row == 13){
        if (_infomodel.result.carStockState == 20) {
            [ShowMessage showHintMessage:@"入库后此信息不可更改" duration:2.0 withRemindId:remindWarning];
            return;
        }
        NSMutableArray *colornames = [NSMutableArray array];
        NSMutableArray *colorImages = [NSMutableArray array];
        for (Basecaroutcoloroptions *dic in self.otherModel.result.baseCarOutColorOptions) {
            [colornames addObject:dic.colorName];
            [colorImages addObject:dic.colorCode];
            [self.colorsArray addObject:dic.colorId];
            
        }
        [self creatChooseColor:colornames ColorValue:colorImages tag:0];

    }else if (indexPath.row == 14){
        NSMutableArray *colornames = [NSMutableArray array];
        NSMutableArray *colorImages = [NSMutableArray array];
        for (Basecarincoloroptions *dic in self.otherModel.result.baseCarInColorOptions) {
            [colornames addObject:dic.colorName];
            [colorImages addObject:dic.colorCode];
        }
        
        [self creatChooseColor:colornames ColorValue:colorImages tag:1];
        
    }else if (indexPath.row == 15){
        NSMutableArray *typeNames = [NSMutableArray array];
        self.typeIds = [NSMutableArray array];
        for (NSDictionary *dic in self.otherModel.result.baseCarTypeOptions) {
            baseCarTypeOptions *type = [baseCarTypeOptions mj_objectWithKeyValues:dic];
            [typeNames addObject:type.carTypeName];
            [self.typeIds addObject:type.carTypeId];
        }
        [self creatChoose:typeNames tag:6];
        
    }else if (indexPath.row == 16){
        NSMutableArray *names = [[NSMutableArray alloc]initWithObjects:@"自动",@"手动", nil];
        [self creatChoose:names tag:7];
        
    }else if (indexPath.row == 18){
        
        NSMutableArray *names = [[NSMutableArray alloc]initWithObjects:@"L",@"T", nil];
        [self creatChoose:names tag:8];
    }else if (indexPath.row == 22){
        if (_infomodel.result.carStockState == 20) {
            [ShowMessage showHintMessage:@"入库后此信息不可更改" duration:2.0 withRemindId:remindWarning];
            return;
        }
        NSMutableArray *userNames = [NSMutableArray array];
        self.useKeys = [NSMutableArray array];
        for (NSDictionary *dic in self.otherModel.result.baseCarPurposeOptions) {
            Basecarpurposeoptions *user = [Basecarpurposeoptions mj_objectWithKeyValues:dic];
            [userNames addObject:user.purposeValue];
            [self.useKeys addObject:user.purposeKey];
        }
        [self creatChoose:userNames tag:9];
    }
    
    
}

-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
    NSString *text = [textField.text stringByReplacingCharactersInRange:range withString:string];
    
    if (textField.tag == 2) {
        
        if ([string isEqualToString:@"q"] ||[string isEqualToString:@"Q"] ||[string isEqualToString:@"i"] ||[string isEqualToString:@"I"]||[string isEqualToString:@"o"]||[string isEqualToString:@"O"]) {
            return NO;
        }
        if ([DataCheck isLegalHKDemailCharacterRegister:string] == NO) {
            if (string.length == 0 ){
                _carNum = text;
                return YES;
                
            }
            return [DataCheck isLegalHKDemailCharacterRegister:string];
        }
        

        if (text.length > 17) {
            return NO;
        }
        
        char commitChar = [string characterAtIndex:0];
        if ((commitChar > 96 && commitChar < 123) || (commitChar > 47 && commitChar < 58) || (commitChar > 64 && commitChar < 91)){
            
            NSString * uppercaseString = string.uppercaseString;
            
            NSString * str1 = [textField.text substringToIndex:range.location];
            
            NSString * str2 = [textField.text substringFromIndex:range.location];
            
            textField.text = [NSString stringWithFormat:@"%@%@%@",str1,uppercaseString,str2].uppercaseString;
            
            _carNum = [NSString stringWithFormat:@"%@%@%@",str1,uppercaseString,str2].uppercaseString;
            
            return NO;
        }
        
        
        return YES;
        
    }else if (textField.tag == 21){
        
        if ([DataCheck isLegalHXAccountCharacter:string] == NO) {
            if (string.length == 0 ){
                _zeroPrice = text;
                return YES;
                
            }
            return [DataCheck isLegalHXAccountCharacter:string];
        }
        if ([text returnRealWithFloatLength:2] == YES) {
            _zeroPrice = text;
        }
        
        return  [text returnRealWithFloatLength:2];
        
        
    }else if (textField.tag == 3){
        
        _carTitle = [NSString stringWithFormat:@"%@%@",_carBrangName,text];
        
    }else if (textField.tag == 5){
        if ([DataCheck isLegalHXAccountCharacter:string] == NO) {
            if (string.length == 0 ){
                _kilometre = text;
                return YES;
                
            }
            return [DataCheck isLegalHXAccountCharacter:string];
        }
        if ([text returnRealWithFloatLength:4] == YES) {
            _kilometre = text;
        }
        
        return [text returnRealWithFloatLength:4];
        
    }else if (textField.tag == 17){
        
        if ([DataCheck isStringPureNumber:string] == NO) {
            if (string.length == 0 ){
                _TransferNum = text;
                return YES;
                
            }
        }
        _TransferNum = text;
        return [DataCheck isStringPureNumber:text];
        
    }else if (textField.tag == 18){
        if ([DataCheck isLegalHXAccountCharacter:string] == NO) {
            if (string.length == 0 ){
                _outputVolume = text;
                return YES;
                
            }
            return [DataCheck isLegalHXAccountCharacter:string];
        }
        if ([text returnRealWithFloatLength:1] == YES) {
            _outputVolume = text;
        }
        return [text returnRealWithFloatLength:1];
        
    }
    return YES;
}
-(void)textFieldDidEndEditing:(UITextField *)textField{
    if (textField.tag == 5) {
        [self loadCarAbountValue];
    }
}

-(void)rightItemClick{
    
    [[[UIApplication sharedApplication] keyWindow] endEditing:YES];//关闭键盘
    [self updateCarInfo];
}

//单个信息
-(void)creatChoose:(NSMutableArray *)titles tag:(NSInteger)tag{
    
    PickCustomView *pickerSingle = [[PickCustomView alloc]init];
    pickerSingle.tag = tag;
    pickerSingle.pickerViewHeight = 300;
    [pickerSingle setDataArray:titles];
    [pickerSingle setDefalutSelectRowStr:titles[0]];
    [pickerSingle setDelegate:self];
    [pickerSingle show];
    [self.view endEditing:YES];
}
-(void)customPickView:(PickCustomView *)customPickView selectedTitle:(NSString *)selectedTitle index:(NSInteger)index{
    
    if (customPickView.tag == 0) {
        _markName = selectedTitle;
        MarketModel *model = self.marketArray[index];
        _markID = model.regionId;
        [self.tableview reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:0 inSection:0]] withRowAnimation:UITableViewRowAnimationNone];

    }else if (customPickView.tag == 4){
        
        _License = selectedTitle;
        if ([selectedTitle isEqualToString:@"已上牌"]) {
            _LicenseID = @"1";
            [self setCarDate];
        }else if ([selectedTitle isEqualToString:@"未上牌"]){
            _LicenseID = @"2";
            _firstDate =  _checkDate = _bizDate = _strongDate  = @"";

        }else if ([selectedTitle isEqualToString:@"新车"]){
            _LicenseID = @"3";
            _firstDate =  _checkDate = _bizDate = _strongDate = @"";

        }
        [self.tableview reloadData];
        
    }else if (customPickView.tag == 5){
        _keyNum = selectedTitle;
        [self.tableview reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:12 inSection:0]] withRowAnimation:UITableViewRowAnimationNone];

    }else if (customPickView.tag == 6){
        _carType = selectedTitle;
        _carTypeId = [self.typeIds[index] integerValue];
        [self.tableview reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:15 inSection:0]] withRowAnimation:UITableViewRowAnimationNone];

    }else if (customPickView.tag == 7){
        _boxType = selectedTitle;
        [self.tableview reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:16 inSection:0]] withRowAnimation:UITableViewRowAnimationNone];

    }else if (customPickView.tag == 8){
        
        _outType = selectedTitle;
        [self.tableview reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:18 inSection:0]] withRowAnimation:UITableViewRowAnimationNone];

    }else if (customPickView.tag == 9){
        _carUseType = selectedTitle;
        _carUserId = self.useKeys[index];
        [self.tableview reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:22 inSection:0]] withRowAnimation:UITableViewRowAnimationNone];
    }
    
}

//时间
-(void)CreatDateChoose:(NSInteger)tag{
    
    isShowDay=NO;
    PickDateView *pickerDate = [[PickDateView alloc]init];
    pickerDate.tag = tag;
    pickerDate.pickerViewHeight = 300;
//    [pickerDate setIsAddYetSelect:YES];//是否显示至今选项
    [pickerDate setIsShowDay:isShowDay];//是否显示日信息
    NSCalendar *gregorian = [[NSCalendar alloc]
                             initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
    // 获取当前日期
    NSDate* dt = [NSDate date];
    // 指定获取指定年、月、日、时、分、秒的信息
    unsigned unitFlags = NSCalendarUnitYear |
    NSCalendarUnitMonth |  NSCalendarUnitDay |
    NSCalendarUnitHour |  NSCalendarUnitMinute |
    NSCalendarUnitSecond | NSCalendarUnitWeekday;
    NSDateComponents* comp = [gregorian components: unitFlags fromDate:dt];
    [pickerDate setDefaultTSelectYear:comp.year defaultSelectMonth:comp.month defaultSelectDay:comp.day];//设定默认显示的日期
    [pickerDate setDelegate:self];
    [pickerDate show];
}

-(void)pickerDateView:(BasePickView *)pickerDateView selectYear:(NSInteger)year selectMonth:(NSInteger)month selectDay:(NSInteger)day{
    NSString *today;
    if (isShowDay==YES) {
        _dateStr = [NSString stringWithFormat:@"%ld-%ld-%ld",year,month,day];
    }else{
    
        _dateStr = [NSString stringWithFormat:@"%ld-%ld",year,month];
        today = [NSString stringWithFormat:@"%ld-%ld-%ld",year,month,day];
    }
    if (pickerDateView.tag == 0) {
        
        NSDate *now = [NSDate date];
        if ([NRWCarTurnTime compareOneDay:now withAnotherDay:today] == 1 || [NRWCarTurnTime compareOneDay:now withAnotherDay:today] == 0 ) {
            _firstDate = _dateStr;
            [self.tableview reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:7 inSection:0]] withRowAnimation:UITableViewRowAnimationNone];
            NSString *yearNum = [NRWCarTurnTime formateFirstDate:today withFormate:@"yyyy-MM-dd"];
            _checkDate = [NRWCarTurnTime returnDate:today withFormate:@"yyyy-MM-dd" withYearNum:yearNum withType:YES];
            [self.tableview reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:8 inSection:0]] withRowAnimation:UITableViewRowAnimationNone];
            _strongDate = _bizDate = [NRWCarTurnTime returnDate:today withFormate:@"yyyy-MM-dd" withYearNum:yearNum withType:NO];
            self.isExpire = NO;
            [self.tableview reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:9 inSection:0]] withRowAnimation:UITableViewRowAnimationNone];
            [self.tableview reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:10 inSection:0]] withRowAnimation:UITableViewRowAnimationNone];
            [self.tableview reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:11 inSection:0]] withRowAnimation:UITableViewRowAnimationNone];
            [self loadCarAbountValue];

        }else{
    
            [ShowMessage showHintMessage:@"首次上牌时间不能比当前时间大!" duration:2.0 withRemindId:remindWarning];
            return ;
        }

    }else if (pickerDateView.tag == 2){
        _checkDate = _dateStr;
        [self.tableview reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:8 inSection:0]] withRowAnimation:UITableViewRowAnimationNone];
        
    }else if (pickerDateView.tag == 3){
        
        _bizDate = _dateStr;
        [self.tableview reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:10 inSection:0]] withRowAnimation:UITableViewRowAnimationNone];

    }else if (pickerDateView.tag == 4){
        _strongDate = _dateStr;
        [self.tableview reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:11 inSection:0]] withRowAnimation:UITableViewRowAnimationNone];
    }
    
    
}

//获取车辆颜色
-(void)creatChooseColor:(NSMutableArray *)colors ColorValue:(NSMutableArray *)value tag:(NSInteger)tag{
    
    PickCarColorView *pickerColor = [[PickCarColorView alloc]init];
    pickerColor.tag = tag;
    pickerColor.pickerViewHeight = 300;
    [pickerColor setDataArray:colors];
    [pickerColor setColorArray:value];
    [pickerColor setDefalutSelectRowStr:colors[0]];
    [pickerColor setDelegate:self];
    [pickerColor show];
    [self.view endEditing:YES];
}
-(void)carColorPickView:(PickCarColorView *)carColorPickView selectedColor:(NSString *)selectedColor Colorindex:(NSInteger)Colorindex{
    if (carColorPickView.tag == 0) {
        _outsideColor = selectedColor;
        _outSideColorId =  self.colorsArray[Colorindex];
        [self.tableview reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:13 inSection:0]] withRowAnimation:UITableViewRowAnimationNone];

    }else if (carColorPickView.tag == 1){
        
        _insideColor = selectedColor;
        [self.tableview reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:14 inSection:0]] withRowAnimation:UITableViewRowAnimationNone];

    }
    
}

//获取市场
-(void)loadMarketList{
    NSString *url = [NSString stringWithFormat:@"%@%@",Api,marketListApi];
    
    NSDictionary *params = @{
                             @"marketId":[NRWCarUser sharedUser].marketId,
                             
                             };
    [YQNetworking postWithUrl:url refreshRequest:YES cache:NO params:params progressBlock:^(int64_t bytesRead, int64_t totalBytes) {
        
    } successBlock:^(id response) {
        
        if ([response[@"code"] isEqual:@1]) {
            [self.marketArray removeAllObjects];
            NSMutableArray *marketNames = [[NSMutableArray alloc] init];
            NSArray *array = response[@"result"];
            for (NSDictionary *dic in array) {
                MarketModel *model = [[MarketModel alloc] init];
                [model setValuesForKeysWithDictionary:dic];
                [self.marketArray addObject:model];
                [marketNames addObject:model.regionName];
            }
            if (marketNames.count == 0) {

                [ShowMessage showHintMessage:@"暂无车场区域可选!" duration:2.0 withRemindId:remindWarning];

            }else{
           
                [self creatChoose:marketNames tag:0];
            }
        }
        
        
    } failBlock:^(NSError *error) {
        [ShowMessage showHintMessage:@"请求失败!" duration:2.0 withRemindId:remindFail];

    }];
    
    
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
//修改车辆信息
-(void)updateCarInfo{
         
    if (!_shopID) {
        [ShowMessage showHintMessage:@"请选择商铺列表!" duration:2.0 withRemindId:remindWarning];

        return;
    }
    if (self.isPrice == NO) {
        if ([_zeroPrice floatValue] <= 0) {
            [ShowMessage showHintMessage:@"填写零售价！" duration:2.0 withRemindId:remindWarning];
            return;
        }
    }else{
        _zeroPrice = @"0";
    }
    if (_isRequired == YES) {
        if (isEmptyOrNilString(_markID) == YES) {
            [ShowMessage showHintMessage:@"请选择车场区域" duration:2.0 withRemindId:remindWarning];
            return;
        }
        if (isEmptyOrNilString(_kilometre)== YES && 0 < [_kilometre floatValue] < 100.0) {
            [ShowMessage showHintMessage:@"请输入正确里程（0~100）" duration:2.0 withRemindId:remindWarning];
            return;
        }
        if ([_LicenseID isEqualToString:@"1"]) {
            
            if (isEmptyOrNilString(_firstDate) == YES ||isEmptyOrNilString(_checkDate) == YES || isEmptyOrNilString(_strongDate) == YES) {
                [ShowMessage showHintMessage:@"请检查必填日期是否填写" duration:2.0 withRemindId:remindWarning];
                return;
            }
        }
    }
    if ([DataCheck isLegalHKDemailCharacterRegisterVin:_carNum] == YES){
        
    }else{
        [ShowMessage showHintMessage:@"车架号错误请修改！" duration:2.0 withRemindId:remindWarning];
        return;
    }
    NSString *outPut = [NSString stringWithFormat:@"%.1f",[_outputVolume floatValue]];
    if (self.isExpire == YES) {
        _bizDate = @"";
    }
    NSString *car300Str;
    if (self.car300ModelArray.count == 0) {
        car300Str = @"";
    }else{
        car300Str = [self.car300ModelArray toJSONString];
    }
    if (self.isRequired == YES) {
        if (isEmptyOrNilString(_boxType) == YES) {
            [ShowMessage showHintMessage:@"请选择变速箱类型！" duration:2.0 withRemindId:remindWarning];
            return;
            
        }
    }
    
    NSDictionary *params = @{
                             @"carId":self.infomodel.result.carId,
                             @"regionId":_markID,
                             @"marketId":[NRWCarUser sharedUser].marketId,
                             @"userId":[NRWCarUser sharedUser].userId,
                             @"shopId":_shopID,
                             @"seriesId":@(_seriesID),
                             @"modelId":@(_carModelId),
                             @"brandId":_carBrangID,
                             @"carTitle":_carTitle,
                             @"carVin":_carNum,
                             @"carMileage":_kilometre,
                             @"carLicenceState":_LicenseID,
                             @"carLicenceDate":_firstDate,
                             @"carValidateDate":_checkDate,
                             @"carBusinessInsuranceDate":_bizDate,
                             @"carForceInsuranceDate":_strongDate,
                             @"carKeyNum":_keyNum,
                             @"carOutColor":_outsideColor,
                             @"carInColor":_insideColor,
                             @"carTypeId":@(_carTypeId),
                             @"carGearbox":_boxType,
                             @"carTransferNum":_TransferNum,
                             @"carDisplacement":outPut,
                             @"carInletModel":_outType,
                             @"carRetailPrice":_zeroPrice,
                             @"carPurpose":_carUserId,
                             @"carValuationJson":car300Str
                             };
    EditCarinfoSecondVC *editvc = [[EditCarinfoSecondVC alloc] init];
    editvc.infomodel = self.infomodel;
    editvc.selIndex = self.selIndex;
    editvc.params = params;
    editvc.date = _firstDate;
    editvc.price = _zeroPrice;
    editvc.carMileage = @([_kilometre doubleValue]);
    editvc.carTitle = _carTitle;
    editvc.carLicenceState = _LicenseID;
    editvc.isReject = self.isReject;
    editvc.reasonStr = self.reasonStr;
    editvc.baseCarFuelOptions = self.otherModel.result.baseCarFuelOptions;
    NSMutableArray *baseCarEnvironOptions = [NSMutableArray arrayWithArray:self.otherModel.result.baseCarEnvironOptions];
    editvc.environOptions = baseCarEnvironOptions;
    if ([self.titleL isEqualToString:@"申请入库"]) {
        editvc.isPutOn = YES;
    }else{
        editvc.isPutOn = NO;
    }
    [self.navigationController pushViewController:editvc animated:YES];
   
}


#pragma mark 键盘出现
-(void)keyboardWillShow:(NSNotification *)note
{
    CGRect keyBoardRect=[note.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
    self.tableview.contentInset = UIEdgeInsetsMake(0, 0, keyBoardRect.size.height, 0);
}
#pragma mark 键盘消失
-(void)keyboardWillHide:(NSNotification *)note
{
    self.tableview.contentInset = UIEdgeInsetsZero;

}
-(void)loadCarOtherConfInfo{
    
    NSString *url = [NSString stringWithFormat:@"%@%@",Api,carOtherConfApi];
    [SVProgressHUD show];
    [YQNetworking postWithUrl:url refreshRequest:YES cache:YES params:nil progressBlock:^(int64_t bytesRead, int64_t totalBytes) {
        
    } successBlock:^(id response) {
        self.otherModel = [CarInfoOtherConfModel mj_objectWithKeyValues:response];
        if (self.otherModel.code == 1) {
            
        }else{
            [ShowMessage showHintMessage:@"车辆信息加载失败!" duration:2.0 withRemindId:remindFail];
            [self.navigationController popViewControllerAnimated:YES];

        }
        [SVProgressHUD dismiss];
    } failBlock:^(NSError *error) {
        [ShowMessage showHintMessage:@"请求失败!" duration:2.0 withRemindId:remindFail];
        [SVProgressHUD dismiss];

    }];
}

- (void)routerEventWithName:(NSString *)eventName userInfo:(NSDictionary *)userInfo{
    NSIndexPath *index = userInfo[@"index"];
    if ([eventName isEqualToString:@"ISYES"]) {
        if (index.row == 20) {
            self.isPrice = YES;
            _zeroPrice = @"0";
        }else if (index.row == 9){
            self.isExpire = YES;
        }
        
    }else if ([eventName isEqualToString:@"ISNO"]){
        if (index.row == 20) {
            self.isPrice = NO;
            _zeroPrice = [NSString stringWithFormat:@"%.2f",self.infomodel.result.carRetailPrice];
        }else if (index.row == 9){
            self.isExpire = NO;
        }
    }
    [self.tableview reloadData];
    
}

#pragma mark 车辆估值
-(void)loadCarAbountValue{
    
    if ([_LicenseID isEqualToString:@"2"] || [_LicenseID isEqualToString:@"3"]) {
        return;
    }
    if (isEmptyOrNilString(_firstDate) == YES) {
        return;
    }
    if (isEmptyOrNilString(_kilometre) == YES) {
        return;
    }
    if (!_carModelId) {
        return ;
    }
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    NSString *cityId = [user objectForKey:KMarketAddressId];
    if (isEmptyOrNilString(cityId) == YES) {
        return;
    }
    NSString *urlStr = [NSString stringWithFormat:@"%@%@",Api,car300ValueApi];
    NSDictionary *dic = @{
                          @"mile":_kilometre,
                          @"modelId":@(_carModelId),
                          @"regDate":_firstDate,
                          @"zone":cityId
                          };
    
    [YQNetworking postWithUrl:urlStr refreshRequest:YES cache:NO params:dic progressBlock:^(int64_t bytesRead, int64_t totalBytes) {
        
    } successBlock:^(id response) {
        _car300Model = [NRWCar300Model mj_objectWithKeyValues:response];
        NSString *lowPrice, *highPrice;
        for (car300PriceModel *model in _car300Model.result) {
            
            if ([model.valuationCondition isEqualToString:@"excellent"]) {
                highPrice = model.valuationDealerHighSoldPrice;
            }else if ([model.valuationCondition isEqualToString:@"normal"]){
                lowPrice = model.valuationDealerLowSoldPrice;
            }
            
            [self.car300ModelArray addObject:[model mj_keyValues]];
        }
        
        _car300Value = [NSString stringWithFormat:@"%.2f ~ %.2f",[lowPrice doubleValue],[highPrice doubleValue]];
        [self.tableview reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:19 inSection:0]] withRowAnimation:UITableViewRowAnimationNone];
    } failBlock:^(NSError *error) {
        
    }];
    
}
@end
